package gdconf

import (
	"server_cluster/common/logger"
)

// 战斗子技能配置表

type BattleSubSkillConfig struct {
	SubSkillId    int32    `csv:"Id" gorm:"primary_key;autoIncrement:false"` // 子技能id
	Type          int32    `csv:"Type,omitempty"`
	Tag           IntArray `csv:"Tag,omitempty"`
	EndTime       int32    `csv:"End_Time,omitempty"`
	Target        int32    `csv:"Target,omitempty"`
	ConditionType int32    `csv:"Condition_Type,omitempty"`
	Condition     int32    `csv:"Condition,omitempty"`
	EffectIdList  IntArray `csv:"Skill_Effect,omitempty"` // 子技能效果id列表
}

func (bss *BattleSubSkillConfig) GetEffectIdList() []int32 {
	ret := make([]int32, 0)
	for _, v := range bss.EffectIdList {
		ret = append(ret, v)
	}
	return ret
}

func (bss *BattleSubSkillConfig) TableName() string {
	return "config_battle_sub_skill_logic"
}

func (g *GameDataConfig) saveBattleSubSkillConfig() {
	saveTableToDb[BattleSubSkillConfig](g.Db, readTable[BattleSubSkillConfig](g.CsvPathPrefix+"BattleSkill.csv"))
}

func (g *GameDataConfig) loadBattleSubSkillConfig() {
	g.GameDataMaps.BattleSubSkillConfigMap = make(map[int32]*BattleSubSkillConfig)
	for _, battleSubSkillConfig := range loadTableFromDb[BattleSubSkillConfig](g.Db) {
		g.GameDataMaps.BattleSubSkillConfigMap[battleSubSkillConfig.SubSkillId] = battleSubSkillConfig
	}
	logger.Info("BattleSubSkillConfig Count: %v", len(g.GameDataMaps.BattleSubSkillConfigMap))
}

func GetBattleSubSkillConfig(subSkillId int32) *BattleSubSkillConfig {
	value, exist := CONF.GameDataMaps.BattleSubSkillConfigMap[subSkillId]
	if !exist {
		logger.Error("[ConfigNotFound] BattleSubSkillConfig, subSkillId: %v", subSkillId)
		return nil
	}
	return value
}

func GetBattleSubSkillConfigMap() map[int32]*BattleSubSkillConfig {
	return CONF.GameDataMaps.BattleSubSkillConfigMap
}
